module view {

    export class BagView extends eui.Component {
        bgButton: eui.Button
        itemsGroup: eui.Group
        contentLabel: eui.Label
        public constructor() {
            super()
            this.addEventListener(eui.UIEvent.COMPLETE,this.onComplete,this)
            this.skinName = "resource/skin/BagSkin.exml"
        }

        protected onComplete(): void {
            this.bgButton.addEventListener(egret.TouchEvent.TOUCH_TAP,this.close,this)
            this.showItems()
        }

        private close(): void {
            this.parent.removeChild(this)
        }
        
        private showItems(): void {
            for(var i in gplayer.bag.items) {         
                var item = gplayer.bag.items[i]
                if(!item) {
                    continue
                }
                var btn: eui.Button = new eui.Button()
                btn.skinName = "resource/control/Button3Skin.exml"
                btn.width = 160
                this.itemsGroup.addChild(btn)
                var itemId = item.id
                var stack = item.stack
                btn.label = templateName[itemId] + 'X' + stack
                btn['value'] = itemId
                btn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.itemInfo,this)
            }
        }
        
        private itemInfo(evt: egret.TouchEvent): void {
            var target = evt.target
            var itemId = target.value
            var itemConfig = totalConfig[itemId]
            this.contentLabel.text = itemConfig.name              
        }
    }
}
